package com.rh.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rh.dto.Page;
import com.rh.entity.Student;
import com.rh.mapper.StudentMapper;
import com.rh.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional

public class StudentServiceImpl implements StudentService {
    @Autowired
    private StudentMapper studentMapper;
    @Override
    public void addMethod(Student student) {
        studentMapper.addMethod(student);
    }

    @Override
    public void deleteMethod(Integer studentId) {
    studentMapper.deleteMethod(studentId);
    }

    @Override
    public void updateMethod(Student student) {
    studentMapper.updateMethod(student);
    }

    @Override
    public Page getStudentPage(Integer pageNo, Integer pageSize) {
        Page page = new Page();
        PageHelper.startPage(pageNo,pageSize);
        List<Student> methodAll = studentMapper.getMethodAll();
        PageInfo<Student>info=new PageInfo<Student>(methodAll);
        page.setPageNo(info.getPageNum());
        page.setPageSize(info.getPageSize());
        page.setHasPre(info.isHasPreviousPage());
        page.setHasNext(info.isHasNextPage());
        page.setPageCount(info.getPages());
        page.setCount(info.getTotal());
        page.setPage(info.getList());
        return page;
    }

    @Override
    public Student getMethodAllById(Integer studentId) {
        return studentMapper.getMethodAllById(studentId);
    }
}
